#include "apigui.h"
#include "gui.h"

/* INIT */

apiGui::apiGui(Gui* gui, QObject *parent) : _gui(gui), QObject(parent)
{
	initConnect();
}

apiGui::~apiGui()
{

}

void							apiGui::initConnect()
{
	connect(_gui->_icon.getDialog()->_connectButton, SIGNAL(clicked()), this, SLOT(handleConnect()));
	connect(&_gui->_icon, SIGNAL(changeMode(quint16, bool)), this, SLOT(handleMode(quint16, bool)));
	connect(&_gui->_icon, SIGNAL(config(quint16)), this, SLOT(handleConfig(quint16)));
}

/* !INIT */

/* GETTERS */

const connectInfo 				apiGui::getConnectInfo()
{
	return (connectInfo(QHostAddress(_gui->getIp()), _gui->getPort().toInt()));
}


/* ! GETTERS */

/* TRAY ICON */

void							apiGui::displayMessage(const std::string &titre, const std::string &message)
{
	_gui->_icon.displayMessage(titre, message);
}

void							apiGui::addServer(quint16 id, QString &name)
{
	_gui->_icon.addServer(id, name);
}

void							apiGui::changeName(quint16 id, QString &name)
{
	_gui->_icon.setName(name, id);
}

void							apiGui::removeServer(quint16 id)
{
	_gui->_icon.removeServer(id);
}


/* !TRAY ICON */

/* SLOTS */

void							apiGui::handleConnect()
{
	if (_gui->isInfoValid() > 0)
		_gui->connectError(_gui->isInfoValid());
	else if (_gui->isInfoFilled())
	{
		emit newConnexion(getConnectInfo());
	}
	else
		_gui->connectError();
}

void							apiGui::handleMode(quint16 id, bool mode)
{
	emit changeMode(id, mode);
}

void							apiGui::handleConfig(quint16 id)
{
	emit config(id);
}

/* !SLOTS */